package com.huijinhui.wlmtsys.controller;


import com.huijinhui.wlmtsys.enums.AppHttpCodeEnum;
import com.huijinhui.wlmtsys.pojo.dtos.PageDTO;
import com.huijinhui.wlmtsys.pojo.dtos.ResponseResult;
import com.huijinhui.wlmtsys.pojo.entity.NewsPageQuery;
import com.huijinhui.wlmtsys.pojo.entity.PageQuery;
import com.huijinhui.wlmtsys.pojo.entity.WlmtsysInfo;
import com.huijinhui.wlmtsys.pojo.entity.WlmtsysNews;
import com.huijinhui.wlmtsys.service.InfoService;
import com.huijinhui.wlmtsys.service.NewsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "admin---新闻接口")
@RestController
@RequestMapping("/news")
@RequiredArgsConstructor
@Slf4j
public class NewsController {


    private final NewsService newsService;


    @Operation(summary = "admin---添加新闻接口")
    @PostMapping("/save")
    public void addNews(@RequestBody WlmtsysNews news) {
        log.info("添加新闻接口");
        newsService.addNews(news);
    }

    @Operation(summary = "admin---删除新闻接口")
    @DeleteMapping("/delete/{id}")
    public void deleteNews(@PathVariable("id") Integer id) {
        log.info("删除新闻接口");
        newsService.deleteNews(id);
    }

    @Operation(summary = "admin---修改新闻接口")
    @PutMapping("/update")
    public ResponseResult updateNews(@RequestBody  WlmtsysNews news) {
        log.info("修改新闻接口,{}",news);
        newsService.updateNews(news);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @PostMapping("/upload")
    public ResponseResult uploadNews(@RequestParam("file")MultipartFile multipartFile, @RequestParam("id") Integer newsId) {
        log.info("图片接口,{},id:{}", multipartFile, newsId);
        newsService.uploadNews(multipartFile, newsId);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
    @Operation(summary = "admin---分页查询获取新闻详情接口")
    @GetMapping("/page")
    public PageDTO<WlmtsysNews> queryNewsPage(PageQuery query){
        log.info("分页查询获取新闻详情接口:{}",query);
        return newsService.queryNewsPage(query);
    }
  @Operation(summary = "官网-----新闻查询接口")
  @GetMapping("/list/{lables}")
    public ResponseResult getNewsList(@PathVariable("lables") Integer lables) {
        log.info("新闻查询接口");
        List<WlmtsysNews> list = newsService.getNewsList(lables);
        return ResponseResult.okResult(list);
    }



}

